<div xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:a4j="http://richfaces.org/a4j"
  class="hostInfos">

  <h3>Indexing operations</h3>

   <a4j:outputPanel id="statePolledPanel">
    <c:choose>
      <c:when test="#{esAdmin.isIndexingInProgress()}">
        <div class="processMessage completeWarning">Indexing in progress</div>
      </c:when>
      <c:otherwise>
        <div class="processMessage completeInfo">No indexing in progress</div>
      </c:otherwise>
    </c:choose>
  </a4j:outputPanel>
   <a4j:poll id="statePoll" interval="2000" enabled="true" timeout="60000" render="statePolledPanel" ajaxSingle="true"/> 

    <h:form id="esAdmin">

    <div class="detail">Choose a repository where the indexing operation will apply.</div>
    <div class="bubbleBox">
      Repository:
      <h:selectOneMenu name="j_repo" value="#{esAdmin.repositoryName}">
        <f:selectItems value="#{esAdmin.repositoryNames}"/>
      </h:selectOneMenu>
    </div>

    <h4>Re-indexing the entire repository</h4>

    <div class="detail">Warning depending on your repository size it can be a long operation.
      The Elasticsearch index is first deleted, you will experience incomplete search results
      during the re-indexing.
    </div>
    <div class="bubbleBox">
      <h:commandButton action="#{esAdmin.startReindexAll}" value="Re-index repository"/>
    </div>

    <h4>Re-indexing documents that match a NXQL query</h4>

    <div class="detail">Only documents that match the query are indexed, there is no recursive
      indexation of children nor deletion of spurious documents from the index.
    </div>
    <div class="bubbleBox">
      NXQL query:
      <h:inputText name="j_nxql" value="#{esAdmin.nxql}"/>
      <h:commandButton action="#{esAdmin.startReindexNxql}" value="Re-index"/>
    </div>

    <h4>Re-indexing a document and its children</h4>

    <div class="detail">This will re-index a document and its children recursively.
      Before indexing, the document and its children are removed from Elasticsearch,
      this operation can be used to remove spurious documents from the index.
      You may experience incomplete search results during the re-indexing.
    </div>
    <div class="bubbleBox">
      Document id:
      <h:inputText name="j_docid" value="#{esAdmin.rootId}"/>
      <h:commandButton action="#{esAdmin.startReindexFrom}" value="Re-index"/>
    </div>

    <h3>Other operations</h3>

    <h4>Flush all Elasticsearch indexes</h4>

    <div class="detail">Use this to make sure Elasticsearch flush its indexes to disk.</div>
    <div class="bubbleBox">
      <h:commandButton action="#{esAdmin.flush}" value="Flush"/>
    </div>

    <h4>Optimize all Elasticsearch indexes</h4>

    <div class="detail">The optimize process basically optimizes the index for faster search operations (and relates to
      the number of segments a Lucene index holds within each shard). The optimize operation allows to reduce the number
      of segments by merging them. Ask for a full optimization to a single segment. Note that this can potentially be a
      very heavy operation.
    </div>
    <div class="bubbleBox">
      <h:commandButton action="#{esAdmin.optimize}" value="Optimize"/>
    </div>

  </h:form>

</div>
